/*
 *
 *   This file is part of jSevenBar. Copyright 2011 Alex Volodko
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */
package de.xhelp.jsevenbar.core;

import java.awt.Rectangle;

/**
 * This class deal with the thumbnail of a taskbar entry
 * 
 * @author Alex Volodko
 * 
 */
public class Thumbnail {

	private static native int setThumbnailClip(int hwnd, int left, int top,
			int right, int bottom);

	private static native int setThumbnailTooltip(int hwnd, String text);

	private final int hwnd;
	private String text;
	private Rectangle bounds;

	/**
	 * Getter
	 * 
	 * @return the bounds. <b>null</b> if thumbnail bounds are in the default Windows state
	 */
	public Rectangle getBounds() {
		return bounds;
	}

	public Thumbnail(int hwnd) {
		this.hwnd = hwnd;
		text = "";
	}

	public void setBounds(Rectangle rect) {
		setBounds(rect.x, rect.y, rect.x + rect.width, rect.height);
	}

	public void setBounds(int left, int top, int width, int height) {
		int result = setThumbnailClip(hwnd, left, top, left + width, top
				+ height);
		if (result != JSevenBar.S_OK) {
			throw new IllegalStateException("Return code: " + result);
		}
		bounds = new Rectangle(left, top, width, height);
	}

	/**
	 * Getter
	 * 
	 * @return the text
	 */
	public String getText() {
		return text;
	}
	
	public void restoreToDefaultThumbnail() {
		int result = setThumbnailClip(hwnd, -1, -1, -1, -1);
		if (result != JSevenBar.S_OK) {
			throw new IllegalStateException("Return code: " + result);
		}
		bounds = null;
	}

	public void setText(String text) {
		int result = setThumbnailTooltip(hwnd, text);
		if (result != JSevenBar.S_OK) {
			throw new IllegalStateException("Return code: " + result);
		}
		this.text = text;
	}

}
